import 'package:flutter/widgets.dart';
import 'package:imperius_insights/portal/channels/web.dart';

import 'summary.dart';

enum MobileType {
  MOBILE_2G,
  MOBILE_3G,
  MOBILE_4G,
  MOBILE_5G,
}

enum NetworkType { MOBILE, WIFI, Unknown }

class NetworkInfo {
  final NetworkType networkType;

  NetworkInfo(this.networkType);
}

class WifiNetworkInfo extends NetworkInfo {
  String name;
  final String ssid;
  String mac;
  String innerIp;

  WifiNetworkInfo(NetworkType networkType,
      {@required this.ssid, this.mac, this.name, @required this.innerIp})
      : super(networkType);
}

class ConnectivityInfo {
  NetworkInfo networkInfo;
  String overtIp;

  /// 默认ldns，此外还应有联通/移动/电信,https://nstool.haowu.link/
  String localDns;
  bool available;

  ConnectivityInfo(
      {@required this.networkInfo,
      @required this.overtIp,
      @required this.localDns,
      @required this.available});
}

const int DEFAULT_BENCHMARK_SAMPLE_TIMES = 10;
const int DEFAULT_HEALTH_CHECK_SAMPLE_TIMES = 30;

class MeasurementRequest {
  final String name;
  final String uri;
  String available;
  int sampleTimes;

  MeasurementRequest(this.name,
      {@required this.uri,
      this.sampleTimes = DEFAULT_BENCHMARK_SAMPLE_TIMES,
      this.available});
}

class MeasurementResult {
  final MeasurementRequest measurementRequest;
  Summary summary;

  MeasurementResult(this.measurementRequest, {this.summary});
}

class PerformanceSummary {
  ConnectivityInfo connectivityInfo;
  List<MeasurementResult> measurements;

  PerformanceSummary({this.connectivityInfo, this.measurements});
}

enum EnumErrorType { UnableConnect, ServiceError, Instability }
enum EnumDataFormat { JSON, Unspecific }

class HealthCheckRequest {
  final String name;
  final WebCallableTarget callableTarget;
  Map<String, dynamic> params;
  int sampleTimes;
  EnumDataFormat dataFormat;

  HealthCheckRequest(this.name, this.callableTarget,
      {this.params, this.sampleTimes = DEFAULT_HEALTH_CHECK_SAMPLE_TIMES, this.dataFormat = EnumDataFormat.JSON});
}

class HealthCheckResult {
  HealthCheckRequest healthCheckRequest;
  Summary summary;
  Set<EnumErrorType> errorTypes;
  List<Exception> exceptions;

  HealthCheckResult(this.healthCheckRequest, {this.summary, this.errorTypes, this.exceptions});
}

class HealthCheckSummary {
  ConnectivityInfo connectivityInfo;
  List<HealthCheckResult> healthCheckResults;

  HealthCheckSummary({this.connectivityInfo, this.healthCheckResults});
}

/// https://github.com/jogboms/flutter_spinkit
/// SpinKitDualRing
